Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new INT4 quantization features to model builder #940

Merged
merged 8 commits into from
Nov 1, 2024

Conversation

kunal-vaishnavi
Copy link
Contributor

@kunal-vaishnavi kunal-vaishnavi commented Sep 27, 2024

Description

This PR adds new INT4 quantization features to the model builder.

  1. The model builder can now quantize the embedding layer and the language modeling head to INT4 precision by default.
  2. For already-quantized PyTorch models that are passed to the model builder, any ops that are still created with MatMul can now be quantized to MatMulNBits via RTN.
  3. A new optional flag in the extra options called int4_op_types_to_quantize has been added to allow more flexibility with INT4 quantization.

Motivation and Context

With these PR changes, the size of the ONNX models can be reduced by quantizing the embedding layer and/or the language modeling head.

For the ONNX models built from already-quantized PyTorch models, one example is with using AutoAWQ. AutoAWQ does not quantize the language modeling head. The resulting ONNX model typically contains a MatMul op for the language modeling head. Now, that MatMul op will be quantized via RTN to MatMulNBits to reduce memory.

Copy link

@fajin-corp fajin-corp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@kunal-vaishnavi kunal-vaishnavi merged commit 2c01695 into main Nov 1, 2024
13 checks passed
@kunal-vaishnavi kunal-vaishnavi deleted the kvaishnavi/int4-embeddings branch November 1, 2024 22:43
kunal-vaishnavi pushed a commit that referenced this pull request Nov 5, 2024
As title. This enables support for further reduced quantized model size
and improved runtime efficiency, within acceptable range of accuracy
degradation.

Orthogonal to #940. This PR targets already quantized models in
autoawq/autogptq format that **has** lmhead quantized.
aciddelgado pushed a commit that referenced this pull request Nov 5, 2024
### Description

This PR adds new INT4 quantization features to the model builder.

1. The model builder can now quantize the embedding layer and the
language modeling head to INT4 precision by default.
2. For already-quantized PyTorch models that are passed to the model
builder, any ops that are still created with `MatMul` can now be
quantized to `MatMulNBits` via RTN.
3. A new optional flag in the extra options called
`int4_op_types_to_quantize` has been added to allow more flexibility
with INT4 quantization.

### Motivation and Context

With these PR changes, the size of the ONNX models can be reduced by
quantizing the embedding layer and/or the language modeling head.

For the ONNX models built from already-quantized PyTorch models, one
example is with using AutoAWQ. AutoAWQ does not quantize the language
modeling head. The resulting ONNX model typically contains a `MatMul` op
for the language modeling head. Now, that `MatMul` op will be quantized
via RTN to `MatMulNBits` to reduce memory.
aciddelgado pushed a commit that referenced this pull request Nov 5, 2024
As title. This enables support for further reduced quantized model size
and improved runtime efficiency, within acceptable range of accuracy
degradation.

Orthogonal to #940. This PR targets already quantized models in
autoawq/autogptq format that **has** lmhead quantized.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants